<? if ($c = stack('name')) {

	$s = component_settings($c);

	?><section id="cpn-<?=$c?>" class="cpn-sections"><?
	
	ob_start();
	
	?><div class="blocks"><?

	foreach($d = component_data($c) as $id => $v) {
		
		$class = implode(' ', array_trim_empty_str(array('block', $v['first'], $v['last'], $v['class'])));
		
		?><div id="cpn-<?=$c?>-<?=$id?>" class="<?="$class"?>"><?

			if ($v['image']) { 
			
				if ($v['url']) { $_closer = '</a>';	// has link
				
					?><a href="<?=_completeURL($v['url'])?>" title="<?=h($v['alt'])?>" class="link image"<?=(strpos($v['url'], '://') === false) ? '' : ' target="_blank"'?>><?	
					
				} else { $_closer = '</div>';
				
					?><div class="image"><?
					
				}

				?><img src="<?=$v['image']['fn']?>" width="<?=$v['image']['x']?>" height="<?=$v['image']['y']?>" alt="<?=h($v['alt'])?>" /><?=$_closer?><?
			}
		
			?><div class="desc"><?
				
				switch($_h = (int)$s['show_headers']) {	// making the section title
				
					case 0: break; // no title
					
					case 1: case 2: case 3: case 4: case 5: case 6: // enclose the title into the corresponding H tag
		
				?><h<?=$_h?>><?
				
				if ($v['url']) { $_closer = '</span></a>';	// has link
				
					?><a href="<?=_completeURL($v['url'])?>" title="<?=h($v['alt'])?>" class="link text"<?=(strpos($v['url'], '://') === false) ? '' : ' target="_blank"'?>><span><?	
					
				} else { $_closer = '</span>';
				
					?><span class="text"><?
					
				}
				
				?><?="$v[title]$_closer</h$_h>"?><?
						
						break;
						
					case 7:	// make the custom formatted title
					
						?><?=str_replace(array('{title}', '{url}', '{tip}'), array($v['title'], $v['url'], $v['alt']), $s['header_format'])?><?
					
						break;
			}
				
			if ($v['body']) { 
				?><div class="text"><?=$v['body']?></div><?
			}

			?></div><?
			
			?><div class="clearer"></div><?
					
		?></div><?
	} 
	
	if ($s['clear']) { ?><div class="clearer"></div><? }

	?></div><?
	
	$temp = ob_get_clean();

	if ($s['caption']) { 
	
		?><div class="cpn-sections-caption">
			<?=(strpos($s['caption'], '{sections}') !== false) ? str_replace('{sections}', "</div>$temp<div class=\"cpn-sections-footer\">", $s['caption']).'</div>' : $s['caption'].'</div>'.$temp?>
		<?
		
	} else {
		?><?=$temp?><?
	}
	
	?></section><?
	
unstack();
}